@include('admin.layout.css')
@include('admin.layout.js')




<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">


    <div class="layui-form-item">
{{--        <label class="layui-form-label"> 代理</label>--}}
{{--        <div class="layui-input-inline">--}}
{{--            <input type="radio" name="vip_index" value="0" title="关闭" checked>--}}
{{--            <input type="radio" name="vip_index" value="1" title="启用" >--}}
{{--        </div>--}}


        <label class="layui-form-label"> 是否开启</label>
        <div class="layui-input-inline">
            <input type="radio" name="quxian_auth" value="0" title="关闭" checked>
            <input type="radio" name="quxian_auth" value="1" title="开启" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">城市联动</label>
        <div class="layui-input-inline" >
            <select name="quxian_province_val" lay-verify="required" lay-search="" lay-skin="select" lay-filter="province">
                <option value="">请选择省</option>
                @forelse ($province as $vo)
                    <option @if ($vo['id'] == $user_info['quxian_province_val'] && $user_info['quxian_province_val']!=0) selected @endif value="{{$vo['id']}}">{{$vo['name']}}</option>
                @endforeach
            </select>
        </div>
        <div class="layui-input-inline" >
            <select name="quxian_city_val" lay-verify="required" lay-search="" lay-skin="select" lay-filter="city" id="city">
                <option value="">请选择城市</option>
                @forelse ($city as $vo)
                    <option @if ($vo['id'] == $user_info['quxian_city_val'] && $user_info['quxian_city_val']!=0) selected @endif value="{{$vo['id']}}">{{$vo['name']}}</option>
                    @endforeach
            </select>
        </div>
        <div class="layui-input-inline" >
            <select name="quxian_area_val" lay-verify="required" lay-search=""lay-skin="select" lay-filter="area" id="area">
                <option value="">请选择区县</option>
                @forelse ($area as $vo)
                    <option @if ($vo['id'] == $user_info['quxian_area_val'] && $user_info['quxian_area_val']!=0) selected @endif value="{{$vo['id']}}">{{$vo['name']}}</option>
                    @endforeach
            </select>
        </div>
    </div>







    <input type="hidden" name="user_id" value="{{$user_id}}">

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="submit" id="submit" value="确认">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="取消">
    </div>

</div>


<script>




    layui.use(['laydate','form'], function() {
        let form = layui.form;
        form.on('submit(submit)', function(data){
            Api.add("{{route('admin.users.user_quxian')}}",data.field,function(res){
                if (res.code !== 200){
                    Utils.errorToast(res.msg);
                    return;
                }
            });
        });

        var province_val =$("#province option:selected").text();
        var city_val = $("#city option:selected").text();
        var area_val = $("#arae option:selected").text();
        form.on('select(province)',function(data) {
            province_val = data.elem[data.elem.selectedIndex].text;
            console.log(province_val);
            //监听省份的选择做多级联动 <option value="">请选择镇区</option>
            $("#city").html('<option value="">请选择市/县</option>');
            $("#area").html('<option value="">请选择镇区</option>');
            //发送ajax
            $.ajax({
                url:"{{route('admin.users.get_child_area')}}",
                data:{parent_id:data.value},
                type: 'POST',
                dataType: 'json',
                success: function(result) {
                    if (result.code == 200) {
                        $("#city").append(result.data.option);
                        form.render('select'); //刷新select选择框渲染
                    }
                }
            });
        });
        form.on('select(city)',function(data) {
            city_val = data.elem[data.elem.selectedIndex].text;
            //监听城市获取县区
            $("#area").html('<option value="">请选择镇区</option>');
            //发送ajax
            $.ajax({
                url:"{{route('admin.users.get_child_area')}}",
                data:{parent_id:data.value},
                type: 'POST',
                dataType: 'json',
                success: function(result) {
                    if (result.code == 200) {
                        $("#area").append(result.data.option);
                        form.render('select'); //刷新select选择框渲染
                    }
                }
            });
        });
        form.on('select(area)',function(data) {
            area_val = data.elem[data.elem.selectedIndex].text;
        });
    });
</script>
